package com.jf3q.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jf3q.admin.service.impl.OrderServiceImpl;
import com.jf3q.admin.utils.vo.AjaxResultVO;
import com.jf3q.common.domain.EduOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @author ASUS
 * @date 2024/6/3
 * @apiNote
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    OrderServiceImpl orderService;

    @PostMapping("/page")
    public AjaxResultVO page(@RequestBody EduOrder order,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = ""+Integer.MAX_VALUE) Integer pageSize){
        LambdaQueryWrapper<EduOrder> memberWrapper=new LambdaQueryWrapper<>();
        if (!ObjectUtils.isEmpty(order)){
            if (!ObjectUtils.isEmpty(order.getOrderNo())){
                memberWrapper.eq(EduOrder::getOrderNo, order.getOrderNo());
            }
            if (!ObjectUtils.isEmpty(order.getCourseTitle())){
                memberWrapper.eq(EduOrder::getCourseTitle,order.getCourseTitle());
            }
            if (!ObjectUtils.isEmpty(order.getTeacherName())){
                memberWrapper.eq(EduOrder::getTeacherName, order.getTeacherName());
            }
            if (!ObjectUtils.isEmpty(order.getMobile())){
                memberWrapper.eq(EduOrder::getMobile,order.getMobile());
            }
            if (!ObjectUtils.isEmpty(order.getStatus())){
                memberWrapper.eq(EduOrder::getStatus,order.getStatus());
            }
            memberWrapper.orderByDesc(EduOrder::getEduModified);
        }
        Page<EduOrder> page=orderService.page(new Page<>(pageNum,pageSize),memberWrapper);
        return AjaxResultVO.success(page);
    }
}
